package com.ruoyi.web.controller.api.user;

import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.system.domain.bo.PUserExtractBo;
import com.ruoyi.system.domain.bo.UserRechargeRequest;
import com.ruoyi.system.domain.vo.WalletVO;
import com.ruoyi.system.service.IPUserBillService;
import com.ruoyi.system.service.IPUserExtractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author: wk
 * @Date: 2022/7/26 16:27
 * @Version: 1.0
 */

@Api(tags = {"前端-金额管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/wallet")
public class WalletApiController {
    private final IPUserExtractService userExtractService;
    private final IPUserBillService billService;

    @ApiOperation("用户提现申请")
    @RepeatSubmit()
    @PostMapping("/add")
    public R<String> add(@Validated(AddGroup.class) @RequestBody PUserExtractBo bo) {
        userExtractService.insertFont(bo);
        return R.ok("申请成功！");
    }

    @ApiOperation("收益看板")
    @PostMapping("get-data")
    public R<Map<String, Object>> getData() {
        Map<String, Object> res = new HashMap<>();
        // 昨日收益、累计收益
        res.put("yesterday", "");
        res.put("total", "");
        return R.ok(res);
    }

    @ApiOperation("用户充值")
    @RepeatSubmit()
    @PostMapping("/user-charge")
    public R<String> userCharge(@Validated(AddGroup.class) @RequestBody UserRechargeRequest rechargeRequest) {
        billService.chargeMoney(rechargeRequest);
        return R.ok("充值成功！");
    }

    @ApiOperation("我的钱包")
    @GetMapping("/myWallet")
    public R<WalletVO> myWallet(@RequestParam("end") String end, PageQuery pageQuery) {
        return R.ok(this.billService.myWallet(end, pageQuery));
    }

}
